package com.itheima.dynamicProxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibAgent implements MethodInterceptor {
    //创建代理对象
    public Object createProxy(Object obj){
        //创建增强内
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(obj.getClass());
        enhancer.setCallback(this);
        //创建代理对象
        return enhancer.create();
    }


    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("售票 准备舞台");
        //热巴在动作
        Object invokeSuper = methodProxy.invokeSuper(o, objects);
        System.out.println("清场 打扫卫生");
        return invokeSuper;
    }
}
